package com.aooci.ordercat.desktop.view;

import java.net.URL;
import java.util.ResourceBundle;

import com.aooci.ordercat.desktop.OrdercatMain;
import com.aooci.ordercat.desktop.SystemConstant;
import com.aooci.ordercat.domain.DiningTable;
import com.aooci.ordercat.enums.DiningTableStatus;
import com.aooci.ordercat.vo.OperatedOrderVo;
import com.aooci.ordercat.vo.OrderedItemVo;
import com.aooci.ordercat.vo.TakeawayVo;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.geometry.Insets;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.CornerRadii;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.stage.Stage;

@SuppressWarnings("restriction")
public class ChangeTableController implements Initializable {
//	private OrdercatMain ordercatMain;
//	private AnchorPane tableButtonsPane;
//	private OperatedOrderVo operatedOrderVo;
	//private Label tableNumber;


	public void initialize(URL arg0, ResourceBundle arg1) {

	}
	
	public void init(OrdercatMain ordercatMain, AnchorPane tableButtonsPane, OperatedOrderVo operatedOrderVo, Label tableNumber){
//		this.setOrdercatMain(ordercatMain);
//		this.setTableButtonsPane(tableButtonsPane);
//		this.setOperatedOrderVo(operatedOrderVo);
		//this.tableNumber = tableNumber;

		//Dining Hall table buttons list
		int lx = 20;
		int ly = 100;
		for(DiningTable table : ordercatMain.getOrderOperationService().loadFreeDiningTablesByCategoryId(1)){
			Button button = new Button();
			button.setText(table.getLabel());
			button.setFont(Font.font ("System", 18));
			button.setPrefWidth(100);
			button.setPrefHeight(60);
			button.setLayoutX(lx);
			button.setLayoutY(ly);
			
			button.setOnAction(new EventHandler<ActionEvent>() {
			    @Override public void handle(ActionEvent e) {
			    	
			    	ordercatMain.getDiningHallTables().get(operatedOrderVo.getDiningTable().getId()).getStyleClass().remove("dininghall_occupied_table");
			    	ordercatMain.getDiningHallTables().get(operatedOrderVo.getDiningTable().getId()).getStyleClass().add("dininghall_free_table");
			    	
			    	ordercatMain.getDiningHallTables().get(table.getId()).getStyleClass().remove("dininghall_free_table");
			    	ordercatMain.getDiningHallTables().get(table.getId()).getStyleClass().add("dininghall_occupied_table");
			    	operatedOrderVo.setDiningTable(ordercatMain.getOrderOperationService().changeTable(operatedOrderVo.getDiningTable(), table.getId()));
			    	tableNumber.setText(operatedOrderVo.getDiningTable().getLabel());
					
					((Stage) button.getScene().getWindow()).close();
			    }
			});
			
			
			if(lx < 600){
				lx += 120;
			}else{
				lx = 20;
				ly += 70;
			}
			tableButtonsPane.getChildren().add(button);
			//this.tableButtons.put(table.getId(), button);
		}
	}
	

//	public void setOrdercatMain(OrdercatMain ordercatMain) {
//		this.ordercatMain = ordercatMain;
//	}
//	
//	
//
//	public void setOperatedOrderVo(OperatedOrderVo operatedOrderVo) {
//		this.operatedOrderVo = operatedOrderVo;
//	}
//
//
//	public void setTableButtonsPane(AnchorPane tableButtonsPane) {
//		this.tableButtonsPane = tableButtonsPane;
//		
//	}
//	
	


}
